package chapter04.demo1;

/**
 * 1.继承
 * 2.重写
 */
class Flower{//花朵类
    String color;//花瓣颜色
    int petalNumber;//花瓣数量
    String petalType;//花瓣类型
    private String flowerTime;// 花期
    public void setFlowerTime(String flowerTime){
        this.flowerTime = flowerTime;
    }
    public String getFlowerTime(){
        return flowerTime;
    }
    public void setColor(String color) {
        this.color = color;//设置花瓣颜色
    }
    public String getColor(){
        return color;
    }
}
// 樱花类继承了花类朵
class Sakura extends Flower{
    String flowerTime;
    public void flowerLanguage(){
        System.out.println("热烈、纯洁、高尚");
    }
    public void setFlowerTime(String flowerTime){//重写
        if (this.color.equals("粉色")){//粉色花朵都是三月
            this.flowerTime = "3月";
        }else{
            this.flowerTime = flowerTime;//用户输入的花期
        }
    }
    public String getFlowerTime(){
        return flowerTime;
    }
}
public class Demo1 {
    public static void main(String[] args) {
        Sakura sakura = new Sakura();
        sakura.setColor("粉色");
        sakura.setFlowerTime("3月-4月");
        System.out.println("粉色樱花花期"+sakura.getFlowerTime());
        sakura.petalNumber = 15;
        sakura.petalType = "单瓣型";
        System.out.println("樱花颜色"+ sakura.getColor());
        sakura.flowerLanguage();
    }
}
